package com.dong.service.impl;

import com.dong.dao.StudentDao;
import com.dong.dao.impl.StudentDaoImpl;
import com.dong.entity.Student;
import com.dong.service.StudentService;
import com.dong.util.Page;

import java.util.List;

/**
 * @author xiaoDong
 * @version 1.0.0
 * @ClassName StudentServiceImpl.java
 * @Description TODO
 * @createTime 2024年05月07日 08:54:00
 */
public class StudentServiceImpl implements StudentService {
    StudentDao studentDao = new StudentDaoImpl();


    @Override
    public Page<Student> selectPage(Page page, String stuName, Integer classId) {

        int count = studentDao.count(stuName, classId);

        List<Student> studentList = studentDao.selectList(page, stuName, classId);

        page.setTotalCount(count);

        page.setDataList(studentList);


        return page;
    }

    @Override
    public boolean editStu(Student student) {
        int count = -1;
        if (student.getId() != -1) {
            //编辑
            count = studentDao.updateStu(student);
        } else {
            //新增
            count = studentDao.addStu(student);
        }

        return count > 0 ? true : false;
    }

    @Override
    public Student stuDetail(int id) {
        return studentDao.stuDetail(id);
    }
}
